package bairui.international.weixin.portal.miniapp.controller.index.message;

import java.util.List;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.querydsl.QSort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.model.uml.model.status.State_UpDown;
import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;

import bairui.international.model.domain.jpa.TB_IndexMessage;
import bairui.international.service.Service_IndexMessage;
import lombok.Getter;

/**
 *
 * 列表
 *
 * @generated
 * 
 * @see STest_C_Index_Message_List_Get 测试
 *
 */
@Controller
public class C_Index_Message_List_Get
 extends SC_Index_Message_List_Get 
{
	
	@Autowired private Service_IndexMessage service_IndexMessage;
	
	/**
	 * Get请求
	 */
	@Action(Get.class)
	@GetMapping(Get.RequestMappingValue)
	public @FomatOutput @ResponseBody Object get(
		ModelMap map, HttpServletRequest request
	) throws Exception {
		List<TB_IndexMessage> messages = service_IndexMessage.list(
				it->it.state.eq(State_UpDown.Uped),
				it->new QSort(it.orderValue.desc())
			).getContent();
		return messages
				.stream()
				.map(it->new Output(it))
				.collect(Collectors.toList());
	}
	
	public static class Output {
		private @Getter Long id;
		private @Getter String message;
		
		public Output(TB_IndexMessage message) {
			this.id = message.getId();
			this.message = message.getMessage();
		}
	}

}
